Duplicated type casts (DTC)

Description:

If you need to access components of some more specific class than the one that a reference variable has, you will have to explicitly cast the reference. If you access more than one component, then type cast has to be repeated multiple times. This complicates the code and makes it less efficient. In this case, it is better to declare an extra local variable of a proper type and assign the casted reference to it.

The option, Maximal number of casts, defines the maximal number of duplicated type casts that will be allowed by DTC. It is set to 1 by default, which means that a warning message will be generated for every duplicated cast.

Incorrect:

if obj is String then
    result := (String(obj).Length = 0) Or (String(obj).EndsWith('*'));

Correct:

var str:String;
...
if obj is String then
begin
    str := String(obj);
    result := (str.Length = 0) Or (str.EndsWith('*'));
end;